import ToolRequest from '@/base/newToolAxios';
import RequestOption from '@/base/RequestOption';
import { getActToolUrl } from '@/base/constant';
import { Dayjs } from 'dayjs';

const tr = new ToolRequest();

export default class LineDao {
  /**
   * 新增项目产线。
   *
   * @param lineName    产线名称
   * @param projectId   项目ID
   * @param createTime  创建时间
   */
  async addLine(lineName: string, projectId: number, createTime: Dayjs) {
    const ro = new RequestOption();
    return await tr.post(
      getActToolUrl(),
      {
        action: 'addLine',
        lineName: lineName,
        projectId: projectId,
        createTime: createTime.format('YYYY-MM-DD HH:mm:ss')
      },
      ro
    );
  }

  /**
   * 根据项目id 查询所有项目产线详情
   *
   * @param projectId  项目Id
   * @param projectType 项目类型
   * @return LineDTO列表
   */
  async findLinesByProjectId(projectId: number, projectType: number) {
    const ro = new RequestOption();
    return await tr.get(
      getActToolUrl(),
      {
        action: 'findLinesByProjectId',
        projectId: projectId,
        projectType: projectType
      },
      ro
    );
  }
  /**
   * 根据产线Id 查询项目产线详情
   *
   * @param lineId  产线Id
   * @return LineDTO
   */
  async findLineByLineId(lineId: number) {
    const ro = new RequestOption();
    return await tr.get(
      getActToolUrl(),
      {
        action: 'findLineByLineId',
        lineId: lineId
      },
      ro
    );
  }
  /**
   * 更新产线节点
   *
   * @param lineId 产线ID
   * @param lineAssignmentList 产线节点列表
   */
  async updateLineAssignment(lineId: number, lineAssignments: Array<any>) {
    const ro = new RequestOption();
    return await tr.post(
      getActToolUrl(),
      {
        action: 'updateLineAssignment',
        lineId: lineId,
        lineAssignments: JSON.stringify(lineAssignments)
      },
      ro
    );
  }

  /**
   * 删除产线与其关联的记录
   *
   * @param lineId 产线id
   */
  async deleteLine(lineId: number) {
    const ro = new RequestOption();
    return await tr.post(
      getActToolUrl(),
      {
        action: 'deleteLine',
        lineId: lineId
      },
      ro
    );
  }

  /**
   * 更新产线名称
   *
   * @param lineId 产线id
   * @param lineName 产线名称
   */
  async updateLineName(lineId: number, lineName: string) {
    const ro = new RequestOption();
    return await tr.post(
      getActToolUrl(),
      {
        action: 'updateLineName',
        lineId: lineId,
        lineName: lineName
      },
      ro
    );
  }

  async copyLine(lineId, lineName: string, projectId: number, createTime: Dayjs) {
    const ro = new RequestOption();
    return await tr.post(
      getActToolUrl(),
      {
        action: 'copyLine',
        lineId: lineId,
        lineName: lineName,
        projectId: projectId,
        createTime: createTime.format('YYYY-MM-DD HH:mm:ss')
      },
      ro
    );
  }
}
